package test01;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-01
 * Time: 19:57
 */
public class test02 {
    public static void main(String[] args) {
        int a = 20;
        int b = 0;
        try {            //此处捕获 div 方法中抛出的异常，可以使程序不终止继续运行，而后在这个语句中处理该异常
            new test02().div(a,b);
        } catch (ArithmeticException e) {
            System.out.println("异常");
        } finally {
            System.out.println("finally");
        }
        System.out.println("继续执行");
    }

    public  void div(int a,int b) throws ArithmeticException {
        if( b== 0) {
            throw new ArithmeticException();//throw关键字：主动抛出异常，一般用在方法中
        }
    }
}
